<?php
/**
 * Created by PhpStorm.
 * User: ocsen
 * Date: 5/6/14
 * Time: 11:45 PM
 */


include 'funcs.php';

$task = @$_GET['task'];

switch($task) {
    case 'login':
        $data = @$_POST['UserLogin'];
        $username = @$data['username'];
        $password = @$data['password'];
        if(doLogin($username, $password)) {
            responseAjax(array(
				"userName" => $username,
                "returnUrl" => BASE_URL . "/solution.php",
                "success" => true
            ));
        }
        else {
            responseAjax(array(
                "UserLogin_username" => array( "Username is incorrect." )
            ));
        }
        break;
    case 'logout':
        doLogout();
        doRedirect(BASE_URL . '/login.php');
        /*responseAjax(array(
            "returnUrl" => BASE_URL,
            "success" => true
        ));*/
        break;
    case 'reportv2':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getBalance($data['companies'], $data['account'], empty($data['value1']) ? $data['date_trade'] : $data['date_value'], empty($data['value1']) ? false : true);

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
	case 'getCenter':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getCenterList();

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
	case 'getThird':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getThirdList($data['center']);

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
	case 'getClient':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getClientList($data['center'],$data['isActive'],$data['searchTag']);

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
	case 'getPortfolio':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getPortfolioList($data['center'],$data['searchTag'],$data['isActive']);

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
	case 'getEmployee':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getEmployeeList();

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
	case 'getPool':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getPoolList($data['center']);

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
	case 'getSecurity':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getSecurityList($data['center']);

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
	case 'getPositionByPortfolio':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getPositionByPortfolio($data['center'],$data['deposit'],$data['manager'],$data['client'],$data['pool'],$data['security'],$data['portfolio'],$data['position'],$data['status'],$data['historical'],$data['valuedate'],$data['nilsecurity'],$data['nilfidu'],$data['nilcash']);

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
	case 'getPositionByClient':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getPositionByClient($data['center'],$data['deposit'],$data['manager'],$data['client'],$data['pool'],$data['security'],$data['portfolio'],$data['position'],$data['status'],$data['historical'],$data['valuedate'],$data['nilsecurity'],$data['nilfidu'],$data['nilcash']);

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
	case 'getPositionByDepositary':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getPositionByDepositary($data['center'],$data['deposit'],$data['manager'],$data['client'],$data['pool'],$data['security'],$data['portfolio'],$data['position'],$data['status'],$data['historical'],$data['valuedate'],$data['nilsecurity'],$data['nilfidu'],$data['nilcash']);

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
	case 'getPositionBymanager':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getPositionBymanager($data['center'],$data['deposit'],$data['manager'],$data['client'],$data['pool'],$data['security'],$data['portfolio'],$data['position'],$data['status'],$data['historical'],$data['valuedate'],$data['nilsecurity'],$data['nilfidu'],$data['nilcash']);

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
	case 'getAllPosition':
        if(!isLogin()) {
            responseAjax(array(
                "success" => false,
                "message" => "Login require"
            ));
        }
        else {
            $data = $_GET;
            $response = soap_getAllPosition($data['center'],$data['deposit'],$data['manager'],$data['client'],$data['pool'],$data['security'],$data['portfolio'],$data['position'],$data['status'],$data['historical'],$data['valuedate'],$data['nilsecurity'],$data['nilfidu'],$data['nilcash']);

            responseAjax(array(
                "success" => true,
                "data" => $response
            ));
        }
        break;
    case 'lang':
        $lang = $_GET['lang'];
        $redirect = $_GET['redirect'];
        changeLanguage($lang);
        doRedirect($redirect);
        break;
}